home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Kit PC World De Ampliacion De Windows 95
/
Kit PC World de ampliacion de Windows 95.iso
/
clarion
/
gauge
/
gauge.z
/
CWSIEVE.CLW
< prev
next >
Wrap
Text File
|
1995-08-21
|
3KB
|
92 lines
Sieve PROGRAM
INCLUDE('KEYCODES.CLW')
MAP
RunSieve
INCLUDE('DDE.CLW')
END
OneShot BYTE(0)
Channel LONG(0)
Start LONG
Stop LONG
Duration REAL
Cycles SIGNED(4000)
CyclesPerMin STRING(10)
Window WINDOW('Clarion for Windows'),AT(,,158,97),CENTER,SYSTEM,GRAY
STRING('Sieve of Eratosthenes Performance Test'),AT(14,21,,)
STRING(@N9),AT(35,45,36,10),USE(CyclesPerMin)
STRING('Cycles / Minute'),AT(70,45,,)
BUTTON('&Run'),AT(35,70,,),USE(?Run)
BUTTON('E&xit'),AT(90,70,,),USE(?Exit)
END
CODE
OPEN(Window)
Channel = DDESERVER('CWSieve')
ACCEPT
CASE EVENT()
OF EVENT:DDEcommand
PRESSKEY(AltR)
OneShot = 1
OF EVENT:Accepted
CASE FIELD()
OF ?Run
DO SieveTest
IF OneShot THEN RETURN.
OF ?Exit
RETURN
END
END
END
DDECLOSE(Channel)
SieveTest ROUTINE
SETCURSOR(CURSOR:Wait)
DISABLE(?Run,?Exit)
CyclesPerMin = 0
DISPLAY
Start = CLOCK()
LOOP UNTIL CLOCK() > Start.
Start = CLOCK()
RunSieve
Stop = CLOCK()
Duration = (Stop - Start) / 100 !Calculate time used
CyclesPerMin = Cycles * 60 / Duration !Calculate cycles per minute
DISPLAY
SETCLIPBOARD(CyclesPerMin)
ENABLE(?Run,?Exit)
SETCURSOR(CURSOR:Arrow)
RunSieve PROCEDURE !Sieve of Eratosthenes
ArraySize EQUATE(1000) !Array size
Flag BYTE,DIM(ArraySize) !Array of flags
Count SIGNED !Number of primes
Prime SIGNED !Next prime
I SIGNED !Loop counter
K SIGNED !Step size
CODE
LOOP Cycles TIMES !Do multiple iterations
Count = 0 !Clear prime counter
CLEAR(Flag,1) !Set all flags on
LOOP I = 1 TO ArraySize !Sift out the non-primes
IF Flag[I] ! For flags that are on
Prime = I + I + 1 ! Set the next prime
K = I + Prime ! Set step count
LOOP WHILE K <= ArraySize ! Loop through remainder
Flag[K] = 0 ! Turning off flags
K += Prime ! Jump to next step
END ! End the loop
Count += 1 !Increment prime counter
END ! End the IF
END !End the LOOP
END !End the outside LOOP
RETURN !Return to caller